package org.ipti.br.tag.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author tarcisio
 */
@Entity
public class Plan extends AbstractEntity{
    
    @ManyToOne
    @JoinColumn(name="season_id")
    private Season season;

    @ManyToOne
    @JoinColumn(name = "discipline_id")
    private Discipline discipline;
    
    @Column(name="plan_year")
    private int planYear;
    
    @ManyToOne
    @JoinColumn(name = "organization_id")
    private Organization organization;
    
    @ManyToOne
    @JoinColumn(name = "unity_id")
    private Unity unity; 
    
    public Plan() {
    }

    @Override
    public void generateHash(){
        if(getId() == null){
            String hash = ""
                    + ((this.getSeason() != null) ? this.getSeason().getId() : null)
                    + ((this.getDiscipline() != null) ? this.getDiscipline().getId() : null)
                    + ((this.getOrganization() != null) ? this.getOrganization().getId() : null)
                    + ((this.getUnity() != null) ? this.getUnity().getId() : null)
                    + this.getPlanYear();
            this.setId(Long.valueOf(EncryptionUtil.encrypt(hash).hashCode()));
        }
    }

    public Plan(Season season, Discipline discipline, int planYear, Organization organization, Unity unity) {
        this.season = season;
        this.discipline = discipline;
        this.planYear = planYear;
        this.organization = organization;
        this.unity = unity;
    }

    public Discipline getDiscipline() {
        return discipline;
    }

    public void setDiscipline(Discipline discipline) {
        this.discipline = discipline;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public Unity getUnity() {
        return unity;
    }

    public void setUnity(Unity unity) {
        this.unity = unity;
    }
    
    public int getPlanYear() {
        return planYear;
    }

    public void setPlanYear(int planYear) {
        this.planYear = planYear;
    }

    public Season getSeason() {
        return season;
    }

    public void setSeason(Season season) {
        this.season = season;
    }
    
}
